package com.javaweb.ser;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.javaweb.utils.DB;
import com.jspsmart.upload.SmartUpload;

/**
 * Servlet implementation class BaseInfo
 */
@WebServlet("/BaseInfo.do")
public class BaseInfo extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BaseInfo() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String sb=request.getParameter("sb");
		System.out.println(sb);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		SmartUpload smartUpload=new SmartUpload(); 
		smartUpload.initialize(getServletConfig(), request,response);
		String sb=smartUpload.getRequest().getParameter("sb");
		System.out.println(sb);
		String name=request.getParameter("name");
		System.out.println(name);
		String sex=request.getParameter("sex");
		String birthday=request.getParameter("birthday");
		String credit_number=request.getParameter("credit_number");
		String nation=request.getParameter("nation");
		String stdno=request.getParameter("stdno");
		String phone=request.getParameter("phone");
		String email=request.getParameter("email");
		String school=request.getParameter("school");
		String university=request.getParameter("university");
		String major=request.getParameter("major");
		String totalYear=request.getParameter("total_study_year");
		String enterYear=request.getParameter("type");
		boolean result=false;
		
		DB.getCon();
		List<Object> params=new ArrayList<>();
		params.add(name);
		params.add(sex);
		params.add(birthday);
		params.add(credit_number);
		params.add(nation);
		params.add(stdno);
		params.add(major);
		params.add(enterYear);
		params.add(school);
		params.add(phone);
		params.add(email);
		params.add(totalYear);
		for(Object ob:params) {
			System.out.println(ob);
		}
		try {
//			result=DB.update("INSERT INTO jsp_apply(" + 
//					"applyName," + 
//					"applySex," + 
//					"appliyBirthday," + 
//					"applyCreditCard," + 
//					"applyNation," + 
//					"applyStuno," + 
//					"applyMajor," + 
//					"applyEnterSchool," + 
//					"applyAcademy," + 
//					"applyPhone," + 
//					"applyEmail," + 
//					"applyIssition" +  
//					") VALUES(?,?,?,?,?,?,?,?,?,?,?,?)", params);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		DB.disConnect();
//		if(result) {
//			request.setAttribute("message", "success");
//			request.getSession().setAttribute("username", name);
//			request.getSession().setAttribute("IDCard", credit_number);
//			response.sendRedirect("Index/selectTestPlace.jsp");
//		}else {
//			request.setAttribute("message", "false");
//			request.getSession().setAttribute("testname", name);
//			request.getSession().setAttribute("IDCard", credit_number);
//			response.sendRedirect("Index/information.jsp");
//		}
		
	}

}
